package org.lib.authservice.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.springframework.security.core.GrantedAuthority;

import lombok.Data;

/**
 * 用户角色
 * @author ben
 * @date 2021-10-21 14:41:34 CST
 */
@Entity
@Data
public class Role implements GrantedAuthority {

	private static final long serialVersionUID = 211021L;

	public static final String PREFIX = "ROLE_";
	
	//
	// 字段
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(nullable = false, unique = true)
	private String name;

	@Column(insertable = false, columnDefinition = "DATETIME DEFAULT NOW()")
	private Date createTime;

	@Column(insertable = false, updatable = false, columnDefinition = "DATETIME DEFAULT NOW() ON UPDATE NOW()")
	private Date updateTime;

	@Override
	public String toString() {
		return this.name;
	}
	
	//
	// 重写接口的方法
	
	@Override
	public String getAuthority() {
		return this.name;
	}

}
